package com.yfl.tingyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yfl.tingyu.pojo.HostPower;
import com.yfl.tingyu.mapper.HostPowerMapper;
import com.yfl.tingyu.service.IHostPowerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-05-30
 */
@Service
public class HostPowerServiceImpl extends ServiceImpl<HostPowerMapper, HostPower> implements IHostPowerService {

    @Override
    public Boolean hostPowerSet(Integer[] hpid, HostPower hostPower) {


        QueryWrapper<HostPower> qw=new QueryWrapper<>();
        qw.in("hostid",hpid);
        baseMapper.delete(qw);

        for (Integer integer : hpid) {
            hostPower.setHostid(integer);
            int row = baseMapper.insert(hostPower);
            if (row == 0){
                return false;
            }

        }

        return true;
    }
}
